package com.whnk.job.task;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;

import java.sql.CallableStatement;
import java.sql.SQLException;
import java.sql.Types;


/**
 * @author Tong
 */
@Component("subDemoTask03")
public class SubDemoTask03 extends BaseTask {
    private final Logger logger = LoggerFactory.getLogger(SubDemoTask03.class);

    public void start(String param) {
        doModelScript(param);
    }

    @Override
    protected String getProcedureInfo() {
//        String param = "M002";
//        System.out.println("~~~~~getProcedureInfo03~~~~只有入参M002");
//        return "{call " + procedureName + "('" + param + "')}";

//        System.out.println("~~~~~getProcedureInfo03~~~~只有出参M003");
//
//        return "{call " + procedureName + "(?)}";

        logger.info("~~~~~getProcedureInfo03~~~~出入参都有M004");
        return "{call " + procedureName + "(?, ?)}";
    }

    @Override
    protected void getResultInfo(CallableStatement csInAndOut) throws SQLException {
        logger.info("~~~~~subDemoTask03~~~~");
        // 只有出参
//        System.out.println("返回参数" + csInAndOut.getString("model_script_out"));
//        System.out.println("返回参数" + csInAndOut.getString(1));

        // 第二个出参
        logger.info("返回参数" + csInAndOut.getString(2));
        logger.info("返回参数" + csInAndOut.getString("model_script_out"));
    }

    @Override
    protected void setInAndOutParam(CallableStatement csInAndOut) throws SQLException {
        // 只有出参
//        csInAndOut.registerOutParameter(1, java.sql.Types.VARCHAR); //第一位为出参，类型为VARCHAR

        // 第一个入参，第二个出参
        csInAndOut.setString(1, "M001");
        csInAndOut.setString(2, "20211123");
//        csInAndOut.registerOutParameter(2, Types.VARCHAR);
    }

    @Override
    protected boolean readExecutorResult() {
        return true;
    }
}
